package com.app.couponsharelife.ui.main.home.fragment
import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.graphics.Paint
import android.graphics.drawable.AnimationDrawable
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager.widget.ViewPager
import com.alibaba.baichuan.android.trade.AlibcTrade
import com.alibaba.baichuan.android.trade.callback.AlibcTradeCallback
import com.alibaba.baichuan.android.trade.model.AlibcShowParams
import com.alibaba.baichuan.android.trade.model.OpenType
import com.alibaba.baichuan.android.trade.page.AlibcPage
import com.alibaba.baichuan.trade.biz.AlibcConstants
import com.alibaba.baichuan.trade.biz.context.AlibcResultType
import com.alibaba.baichuan.trade.biz.context.AlibcTradeResult
import com.alibaba.baichuan.trade.biz.core.taoke.AlibcTaokeParams
import com.alibaba.baichuan.trade.biz.login.AlibcLogin
import com.alibaba.baichuan.trade.biz.login.AlibcLoginCallback
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions
import com.google.android.material.appbar.AppBarLayout
import com.hwangjr.rxbus.annotation.Subscribe
import com.hwangjr.rxbus.annotation.Tag
import com.hwangjr.rxbus.thread.EventThread
import com.app.couponsharelife.R
import com.app.couponsharelife.base.LazyFragment
import com.app.couponsharelife.data.bean.*
import com.app.couponsharelife.data.remote.retrofit.RetrofitWorker
import com.app.couponsharelife.data.remote.retrofit.exception.OtherException
import com.app.couponsharelife.manage.Contacts
import com.app.couponsharelife.ui.listener.MyMultiPurposeListener
import com.app.couponsharelife.ui.main.home.HomeFragment
import com.app.couponsharelife.ui.main.home.good.GoodDetailActivity
import com.app.couponsharelife.ui.main.home.search.HQTGoodsListActivity
import com.app.couponsharelife.ui.main.home.shopweb.ShopWebActivity
import com.app.couponsharelife.ui.main.home.shopweb.TaoBaoWebActivity
import com.app.couponsharelife.ui.main.home.shopweb.WebActivity
import com.app.couponsharelife.ui.main.shop.DaylongHotSellActivity
import com.app.couponsharelife.ui.main.shop.JDShopActivity
import com.app.couponsharelife.ui.main.shop.PddShopActivity
import com.app.couponsharelife.ui.main.special.BrandSpecialActivity
import com.app.couponsharelife.ui.main.special.BrandSpecialListActivity
import com.app.couponsharelife.ui.main.special.NewManFreeActivity
import com.app.couponsharelife.ui.view.MarqueeView
import com.app.couponsharelife.utils.*
import com.youth.banner.BannerConfig
import com.youth.banner.loader.ImageLoader
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.observers.DisposableObserver
import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.base_refresh_head.*
import kotlinx.android.synthetic.main.choiceness_rvitm.view.*
import kotlinx.android.synthetic.main.choiceness_shoprvitm.view.*
import kotlinx.android.synthetic.main.fragment_choiceness.*
import kotlinx.android.synthetic.main.item_choiceness_top.view.*
import kotlinx.android.synthetic.main.item_home_msrv.view.*
import kotlinx.android.synthetic.main.rvitem_allday_hot.view.*
import kotlinx.android.synthetic.main.rvitem_brand.view.*
import kotlinx.android.synthetic.main.rvitem_brand_nodata.view.*
import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator
import java.text.DecimalFormat
import java.text.SimpleDateFormat
import java.util.*

/**
 *Created by xct on 2018/12/21
 *Description:首页精选fragment
 */
class ChoicenessFragment:LazyFragment(),View.OnClickListener{
    private var mTitles = arrayListOf<String>()

    private var bannerImgList= arrayListOf<TopBanner>()
    private var commonNavigator: CommonNavigator?=null
    private val shopList= arrayListOf<Label>()
    private val msClassList= arrayListOf<ExplosiveSpikeLabel>()
    private var msGoodsList= arrayListOf<TaobaoGoodBean>()
    private var favoriteList= arrayListOf<Favorite>()
    private var goodsList= arrayListOf<TaobaoGoodBean>()
    private var goodsAllDayList= arrayListOf<TaobaoGoodBean>()
    private val msTitleList= arrayListOf<String>()

    private var brandList= arrayListOf<BrandSpecialData>()
    private var msClassID1=""
    private var msClassID2=""
    private var msClassID3=""
    private var msClassID4=""
    private var msClassID5=""
    private var msClassType=1  //1已开始2未开始
    private var msClickIndex=1
    private var favoritesID=""  //普通商品选品库ID
    private var xsjcLink=""  //新手教程链接
    private var msTXTitle="券享生活秒杀商品提醒"
    private var msTXTitle1="券享生活秒杀商品提醒"
    private var msStartTime=""
    private var msStartTime1=""
    private var myShopAdapter:MyShopAdapter?=null
    private var layoutManager:GridLayoutManager?=null
    private var msAdapter:MyMSAdapter?=null
    private var myAdapter:MyAdapter?=null
    private var myHotAdapter:MyHotAdapter?=null
    private var myBrandAdapter:MyBrandAdapter?=null
    private var pageIndex=1
    private var isScrolTop=false
    private var mCurrentState=0
    private val mLasttime = arrayListOf<Long>()
    private val simpleDateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault())
    private var alibcShowParams: AlibcShowParams? = null//页面打开方式，默认，H5，Native
    private var exParams: HashMap<String, String>? = null//yhhpass参数
    private var alibcTaokeParams: AlibcTaokeParams? = null//淘客参数，包括pid，unionid，subPid
    private var homeFragment:HomeFragment?=null
    private var bannerIsStop=false
    private var distance=0
    companion object {
        fun newInstance(homeClassBean:HomeClassBean): ChoicenessFragment {
            val fragment = ChoicenessFragment()
            val bundle=Bundle()
            bundle.putParcelable("Data",homeClassBean)
            fragment.arguments =bundle
            return fragment
        }


    }
    override val viewLayoutId: Int
        get() = R.layout.fragment_choiceness

    override fun initViews() {
        homeFragment=parentFragment as HomeFragment
        mLasttime.add(System.currentTimeMillis())
        distance=(AppUtils.getDisplayMetrics(context!!).widthPixels*0.333).toInt()+10
       homeFragment?.choicenessShopRV?.layoutManager=GridLayoutManager(context,5)
        myShopAdapter=MyShopAdapter()
        homeFragment?.choicenessShopRV?.adapter=myShopAdapter
        layoutManager=GridLayoutManager(context,2)
        layoutManager!!.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
            override fun getSpanSize(position: Int): Int {
                return if (position == 0) {
                    2
                } else {
                    1
                }
            }
        }
        choiceness_rv.layoutManager=layoutManager
        myAdapter=MyAdapter()
        choiceness_rv.adapter=myAdapter
        //myBrandAdapter=MyBrandAdapter()
        choiceness_rv.addOnScrollListener(object :RecyclerView.OnScrollListener(){
            var state=0
            var expanded=true
            override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
                super.onScrollStateChanged(recyclerView, newState)
                //RecyclerView.canScrollVertically(1)的值表示是否能向上滚动，false表示已经滚动到底部
                //RecyclerView.canScrollVertically(-1)的值表示是否能向下滚动，false表示已经滚动到顶部
                isScrolTop=!choiceness_rv.canScrollVertically(-1)
                state=newState
                if (RecyclerView.SCROLL_STATE_IDLE==newState){
                    homeFragment?.visibilityAnim()
                    //Log.e("eeeee","滑动停止")
                }else if(RecyclerView.SCROLL_STATE_SETTLING==newState){
                    //Log.e("eeeee","惯性滑动")
                }else{
                    homeFragment?.goneAnim()
                    //Log.e("eeeee","拖拽滑动")
                }
            }

            override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
                super.onScrolled(recyclerView, dx, dy)
                //Log.e("滑动距离","---->$dy")
                if (dy>80&&expanded){  //上滑
                    expanded=false
                    homeFragment?.appbarLayout?.setExpanded(false)
                }else if(dy<-80&&!expanded){  //下滑
                    expanded=true
                    homeFragment?.appbarLayout?.setExpanded(true)
                }
            }
        })
        setRefresh()
        choiceness_coordinatorLayout.background.alpha=0
        choiceness_appbar.addOnOffsetChangedListener(object :AppBarLayout.OnOffsetChangedListener{
            override fun onOffsetChanged(appBarLayout: AppBarLayout?, verticalOffset: Int) {
//                if (verticalOffset in -10 downTo -127){
//                    choiceness_coordinatorLayout.background.alpha=0-verticalOffset*2
//                }else if (verticalOffset>-10){
//                    choiceness_coordinatorLayout.background.alpha=0
//                }else{
//                    choiceness_coordinatorLayout.background.alpha=255
//                }
                if (verticalOffset>-distance&&bannerIsStop){
                    bannerIsStop=false
                    homeFragment?.choicenessMBanner?.startAutoPlay()
                }else{
                    bannerIsStop=true
                    homeFragment?.choicenessMBanner?.stopAutoPlay()
                }
            }
        })
        choiceness_llMS1.setOnClickListener(this)
        choiceness_llMS2.setOnClickListener(this)
        choiceness_llMS3.setOnClickListener(this)
        choiceness_llMS4.setOnClickListener(this)
        choiceness_llMS5.setOnClickListener(this)
        homeFragment?.choicenessLlXSJC?.setOnClickListener(this)
        homeFragment?.choicenessMBanner?.setOnPageChangeListener(object :ViewPager.OnPageChangeListener{
            override fun onPageScrollStateChanged(state: Int) {

            }

            override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {

            }

            override fun onPageSelected(position: Int) {
                if (bannerImgList.isNotEmpty()){
                    val topBanner=bannerImgList[position]
                    homeFragment?.ivTopBg?.setBackgroundColor(Color.parseColor(topBanner.color?:"#D80729"))
                    homeFragment?.newhomefragViewpager?.setBackgroundColor(Color.parseColor(topBanner.color?:"#D80729"))
                    homeFragment?.ll_BBJ?.setBackgroundColor(Color.parseColor(topBanner.color?:"#D80729"))
                    homeFragment?.appbarLayout?.setBackgroundColor(Color.parseColor(topBanner.color?:"#D80729"))
                }
            }

        })
        getHomeBase(false)
    }

    override fun onClick(v: View?) {
        if (!isScrolTop) {
            choiceness_rv.scrollToPosition(0)
            isScrolTop=true
        }
        when(v?.id){
            R.id.choiceness_llMS1->{
                if (msClickIndex!=1) {
                    resetMSType()
                    msClassType = 1
                    choiceness_tvMs1.setTextColor(resources.getColor(R.color.red_ff038))
                    choiceness_tvMsType1.setTextColor(resources.getColor(R.color.red_ff038))
                    choiceness_tvMsXian1.visibility = View.VISIBLE
                    setMsTitleList(msClassList[0].title?:"")
                    getMsGoods(msClassList[0].favoriteId?:"")
                }
                msClickIndex=1
            }
            R.id.choiceness_llMS2->{
                if (msClickIndex!=2) {
                    resetMSType()
                    msClassType = 1
                    choiceness_tvMs2.setTextColor(resources.getColor(R.color.red_ff038))
                    choiceness_tvMsType2.setTextColor(resources.getColor(R.color.red_ff038))
                    choiceness_tvMsXian2.visibility = View.VISIBLE
                    setMsTitleList(msClassList[1].title?:"")
                    getMsGoods(msClassList[1].favoriteId?:"")
                }
                msClickIndex=2
            }
            R.id.choiceness_llMS3->{
                if (msClickIndex!=3) {
                    resetMSType()
                    msClassType = 1
                    choiceness_tvMs3.setTextColor(resources.getColor(R.color.red_ff038))
                    choiceness_tvMsType3.setTextColor(resources.getColor(R.color.red_ff038))
                    choiceness_tvMsXian3.visibility = View.VISIBLE
                    setMsTitleList(msClassList[2].title?:"")
                    getMsGoods(msClassList[2].favoriteId?:"")
                }
                msClickIndex=3
            }
            R.id.choiceness_llMS4->{
                if (msClickIndex!=4) {
                    resetMSType()
                    msClassType = 2
                    choiceness_tvMs4.setTextColor(resources.getColor(R.color.red_ff038))
                    choiceness_tvMsType4.setTextColor(resources.getColor(R.color.red_ff038))
                    choiceness_tvMsXian4.visibility = View.VISIBLE
                    setMsTitleList(msClassList[3].title?:"")
                    getMsGoods(msClassList[3].favoriteId?:"")
                }
                msClickIndex=4
            }
            R.id.choiceness_llMS5->{
                if (msClickIndex!=5) {
                    resetMSType()
                    msClassType = 2
                    choiceness_tvMs5.setTextColor(resources.getColor(R.color.red_ff038))
                    choiceness_tvMsType5.setTextColor(resources.getColor(R.color.red_ff038))
                    choiceness_tvMsXian5.visibility = View.VISIBLE
                    setMsTitleList(msClassList[4].title?:"")
                    getMsGoods(msClassList[4].favoriteId?:"")
                }
                msClickIndex=5
            }
            R.id.choiceness_llXSJC->{
                val intent = Intent(activity, ShopWebActivity::class.java)
                intent.putExtra("url", xsjcLink)
                intent.putExtra("name", "新手教程")
                startActivity(intent)
            }
        }
    }
    private fun setMsTitleList(msTitles:String){
        msTitleList.clear()
        if (msTitles.isNotEmpty()){
            val titles=msTitles.replace("[","").replace("]","").replace("\"","")
            val arr=titles.split(",")
            msTitleList.addAll(arr)
        }
    }
    private fun resetMSType(){
        choiceness_tvMs1.setTextColor(resources.getColor(R.color.black))
        choiceness_tvMsType1.setTextColor(resources.getColor(R.color.gray_66))
        choiceness_tvMsXian1.visibility=View.INVISIBLE
        choiceness_tvMs2.setTextColor(resources.getColor(R.color.black))
        choiceness_tvMsType2.setTextColor(resources.getColor(R.color.gray_66))
        choiceness_tvMsXian2.visibility=View.INVISIBLE
        choiceness_tvMs3.setTextColor(resources.getColor(R.color.black))
        choiceness_tvMsType3.setTextColor(resources.getColor(R.color.gray_66))
        choiceness_tvMsXian3.visibility=View.INVISIBLE
        choiceness_tvMs4.setTextColor(resources.getColor(R.color.black))
        choiceness_tvMsType4.setTextColor(resources.getColor(R.color.gray_66))
        choiceness_tvMsXian4.visibility=View.INVISIBLE
        choiceness_tvMs5.setTextColor(resources.getColor(R.color.black))
        choiceness_tvMsType5.setTextColor(resources.getColor(R.color.gray_66))
        choiceness_tvMsXian5.visibility=View.INVISIBLE
    }
    private fun setIntent(taobaoGoodBean:TaobaoGoodBean){
        val intent = Intent(context, GoodDetailActivity::class.java)
        intent.putExtra("good", taobaoGoodBean)
        startActivity(intent)
    }
    private fun taobaoLogin(){
        showProgressDialog("请稍后")
        val alibcLogin = AlibcLogin.getInstance()
        alibcLogin.showLogin(object : AlibcLoginCallback {
            override fun onSuccess(p0: Int) {
                //showToastMsg("登录成功 ")
                //获取淘宝用户信息
                //Log.i("eee", "获取淘宝用户信息: "+AlibcLogin.getInstance().session)
                dismissProgressDialog()
                //getAliLoginUrl()
                getAliLonginUrl()
            }

            override fun onFailure(p0: Int, p1: String?) {
                //showToastMsg("登录失败")
                dismissProgressDialog()
            }
        })
    }
    override fun lazyLoad() {

    }

    override fun onResume() {
        super.onResume()

    }

    @Subscribe(thread = EventThread.MAIN_THREAD, tags = [(Tag("homefrg_fraeshbobo"))])
    fun refreshData(fresh: String) {
//        Companion.getBroadcast(this)
    }
    private fun setRefresh(){
        hotsale_refreshimg.setImageResource(R.drawable.anim_refresh)
        val animationDrawable=hotsale_refreshimg.drawable as AnimationDrawable
        choiceness_smartrefresh.setEnableNestedScroll(true)
        choiceness_smartrefresh.setOnMultiPurposeListener(object : MyMultiPurposeListener {
            override fun headerReleased() {
                animationDrawable.start()
            }

            override fun headerMoving(percent: Float) {
                setAnima(percent)
            }

            override fun headerFinish() {
                hotsale_refreshimg.setImageResource(R.drawable.refresh_0)
                animationDrawable.stop()
            }

            override fun loadMore() {
                getFavorites(false,favoritesID)
            }

            override fun refresh() {
                pageIndex=1
                //getFavorites(true,favoritesID)
                getHomeBase(true)
                //getBroadcast()
            }

        })
    }
    private fun setAnima(vlaue:Float){
        val layoutParams=hotsale_refreshimg.layoutParams as ConstraintLayout.LayoutParams
        layoutParams.matchConstraintPercentHeight=vlaue/2
        layoutParams.dimensionRatio="0.875:1"
        hotsale_refreshimg.layoutParams=layoutParams
    }
    private fun startShopIntent(bean:Label) {
        val type=bean.type
        val name=bean.name?:""
        val url=bean.link?:""
        var intent: Intent? = null
        when (type) {
            "","CLOSE" -> {
                showToastMsg("正在开发中，敬请期待！")
                return
            }
            "PIN_DUO_DUO" -> { //拼多多
                intent = Intent(activity, PddShopActivity::class.java)
            }
            "CHONG_ZHI" -> {  //充值中心

            }
            "JING_DONG" -> {  //京东
                intent = Intent(activity, JDShopActivity::class.java)
            }
            "Link" -> {  //网页
                intent = Intent(activity, ShopWebActivity::class.java)
                intent.putExtra("url", url)
                intent.putExtra("name", name)
            }
            "H5"->{  //网页
                intent = Intent(activity, ShopWebActivity::class.java)
                intent.putExtra("url", url)
                intent.putExtra("name", name)
            }
            "PRODUCT" -> {  //选品库
                intent = Intent(activity, HQTGoodsListActivity::class.java)
                intent.putExtra("FavoritesID", bean.favoritesId)
                intent.putExtra("ImagUrl",url)
                intent.putExtra("Name", name)
            }
            "ALLDAYHOTSALE" -> {//24小时热销
                intent = Intent(activity, DaylongHotSellActivity::class.java)
                intent.putExtra("Name", name)
            }
            "NEWMENFREE" -> {//新人0元购
                intent = Intent(activity, NewManFreeActivity::class.java)
                intent.putExtra("FavoritesID",bean.favoritesId?:"")
                intent.putExtra("Name",name)
            }
            "BRANDTHEME" -> {//品牌专场
                intent = Intent(activity, BrandSpecialActivity::class.java)
            }
            "MINIPROGRAM" -> {//券享生活严选
                WXMiniProgramUtil.start(context!!)
            }
            "SDK_LINK" -> {
                //goTaoBao(url)
                val relationId = AppUtils.getString(Contacts.ADZONE_ID, "")
                if (relationId.isNotEmpty()) {
                    goTaoBao(url + "&relationId=${relationId}")
                } else {
                    //getAliLonginUrl()
                    taobaoLogin()
                }
            }
            "SDK_H5" -> {
                val relationId = AppUtils.getString(Contacts.ADZONE_ID, "")
                if (relationId.isNotEmpty()) {
                    //val relationId=AppUtils.getString(Contacts.ADZONE_ID, "")
                    intent = Intent(activity, TaoBaoWebActivity::class.java)
                    intent.putExtra("url", url + "&relationId=${relationId}")
                    intent.putExtra("name", name)
                    //goTaoBao(url + "&relationId=${relationId}")
                } else {
                    //getAliLonginUrl()
                    taobaoLogin()
                }
            }
            else -> {
                if (url.startsWith("http")) {
                    intent = Intent(activity, ShopWebActivity::class.java)
                    intent.putExtra("url", url)
                    intent.putExtra("name", name)
                } else {
                    showToastMsg("正在开发中，敬请期待！")
                }
            }
        }
        if (intent!=null) {
            startActivity(intent)
        }
    }
    private fun setMSClassData(){
        if (msClassList.size>4){
            val bean1=msClassList[0]
            choiceness_tvMs1.text=bean1.startTime?:""
            choiceness_tvMsType1.text="已开始"
            msClassID1=bean1.favoriteId?:""
            val bean2=msClassList[1]
            choiceness_tvMs2.text=bean2.startTime?:""
            choiceness_tvMsType2.text="已开始"
            msClassID2=bean2.favoriteId?:""
            val bean3=msClassList[2]
            choiceness_tvMs3.text=bean3.startTime?:""
            choiceness_tvMsType3.text="抢购中"
            msClassID3=bean3.favoriteId?:""
            setMsTitleList(msClassList[2].title?:"")
            resetMSType()
            msClassType = 1
            msClickIndex=3
            choiceness_tvMs3.setTextColor(resources.getColor(R.color.red_ff038))
            choiceness_tvMsType3.setTextColor(resources.getColor(R.color.red_ff038))
            choiceness_tvMsXian3.visibility = View.VISIBLE
            val bean4=msClassList[3]
            choiceness_tvMs4.text=bean4.startTime?:""
            choiceness_tvMsType4.text="即将开始"
            msClassID4=bean4.favoriteId?:""
            msStartTime=bean4.dateTime?:""
            val bean5=msClassList[4]
            choiceness_tvMs5.text=bean5.startTime?:""
            choiceness_tvMsType5.text="即将开始"
            msClassID5=bean5.favoriteId?:""
            msStartTime1=bean5.dateTime?:""
        }
    }
    private fun goTaoBao(url:String) {
        showCountDownProgressDialog("请稍候", 3)
        alibcShowParams = AlibcShowParams(OpenType.Native, false)
        exParams = HashMap()
        exParams!![AlibcConstants.ISV_CODE] = "appisvcode"
        exParams!!["alibaba"] = "阿里巴巴"//自定义参数部分，可任意增删改
        // 若非淘客taokeParams设置为null即可
        val pid = Contacts.ALIMAMA_PID //+ AppUtils.getString(Contacts.ADZONE_ID, "")
        alibcTaokeParams = AlibcTaokeParams()
        alibcTaokeParams?.adzoneid = "65231850041"//AppUtils.getString(Contacts.ADZONE_ID, "")
        alibcTaokeParams?.pid = pid
        alibcTaokeParams?.subPid = pid
        alibcTaokeParams?.extraParams = HashMap()
        (alibcTaokeParams?.extraParams as HashMap<String, String>)["taokeAppkey"] = Contacts.APP_ID
        (alibcTaokeParams?.extraParams as HashMap<String, String>)["relationId"] = AppUtils.getString(Contacts.ADZONE_ID, "")
        if (url == "") {
            showToastMsg("该商品暂时不能购买")
            return
        }
        val rlid="&relationId=${AppUtils.getString(Contacts.ADZONE_ID, "")}"
        AlibcTrade.show(activity, AlibcPage(url+rlid), alibcShowParams, alibcTaokeParams, exParams, object : AlibcTradeCallback {
            override fun onTradeSuccess(tradeResult: AlibcTradeResult) {
                //当addCartPage加购成功和其他page支付成功的时候会回调
                if (tradeResult.resultType == AlibcResultType.TYPECART) {
                    //加购成功
                    showToastMsg("加购成功")
                } else if (tradeResult.resultType == AlibcResultType.TYPEPAY) {
                    //支付成功
//                    Log.d("order", tradeResult.payResult.paySuccessOrders[0])
                }
            }

            override fun onFailure(errCode: Int, errMsg: String) {
                showToastMsg("电商SDK出错,错误码=$errCode / 错误消息=$errMsg")
            }
        })
    }
    private fun getHomeBase(refresh: Boolean){
        showProgressDialog("请稍候")
        val map = HashMap<String, String>()
        RetrofitWorker.retrofitWorker.getNewBase(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(object : DisposableObserver<RemoteResultBean<HomeBaseBean>>(){
                    override fun onComplete() {

                    }
                    override fun onNext(it: RemoteResultBean<HomeBaseBean>) {
                        dismissProgressDialog()
                        if(refresh){
                            choiceness_smartrefresh.finishRefresh()
                        }
                        if (it.data!=null) {
                            xsjcLink=it.data!!.understandLink?:""
                            shopList.clear()
                            shopList.addAll(it.data!!.labels!!)
                            myShopAdapter!!.notifyDataSetChanged()
                            bannerImgList.clear()
                            bannerImgList.addAll(it.data!!.topBanner!!)
                            homeFragment?.choicenessMBanner?.setImageLoader(GlideImageLoader())
                                    ?.setImages(bannerImgList)
                                    ?.setIndicatorGravity(BannerConfig.RIGHT)
                                    ?.setOnBannerListener {
                                        setBannerClic(bannerImgList[it])
                                    }
                                    ?.start()
                            msClassList.clear()
                            msClassList.addAll(it.data!!.explosiveSpikeLabels)
                            setMSClassData()
                            getMsGoods(msClassID3)
                            //getBroadcast()
                            if (it.data!!.favorites!=null&&it.data!!.favorites.isNotEmpty()){
                                favoriteList.addAll(it.data!!.favorites)
                                for (i in 0 until favoriteList.size){
                                    val favorite=favoriteList[i]
                                    if (favorite.name!!.contains("今日")){
                                        pageIndex=1
                                        favoritesID=favorite.favoritesId.toString()
                                        getFavorites(refresh,favoritesID)
                                    }
                                }
                            }
                        }
                    }

                    override fun onError(e: Throwable) {
                        dismissProgressDialog()
                        if(refresh){
                            choiceness_smartrefresh.finishRefresh()
                        }
                        if (e is OtherException){
                            showToastMsg(e.msg)
                        }else{
                            showToastMsg("网络加载出错了！")
                        }
                    }
                })
    }
    private fun getMsGoods(favoritesID:String){
        val map = HashMap<String, String>()
        map["pageNo"]="1"
        map["pageSize"]="5"
        map["favoriteId"]=favoritesID
        RetrofitWorker.retrofitWorker.getMSGoods(map)
                .subscribeOn(Schedulers.io())
                .map { DataUtils().taobaoData(it) }
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(object :DisposableObserver<RemoteResultBean<HomeChiocenGoodsBean>>(){
                    override fun onComplete() {

                    }

                    override fun onNext(it: RemoteResultBean<HomeChiocenGoodsBean>) {
                        if (it.data!=null){
                            msGoodsList.clear()
                            msGoodsList.addAll(it.data!!.recordss as ArrayList<TaobaoGoodBean>)
                            msAdapter!!.notifyDataSetChanged()
                        }
                    }

                    override fun onError(e: Throwable) {
                        if (e is OtherException){
                            showToastMsg(e.msg)
                        }else{
                            showToastMsg("网络加载出错了！")
                        }
                    }

                })
    }

    private fun getFavorites(refresh: Boolean,favoritesID:String){
        val map = HashMap<String, String>()
        val us = AppUtils.getString(Contacts.USERID, "")
        val deviceValues = AppUtils.encryptMD5(AppUtils.getDeviceImei())
        map["userId"] = AppUtils.getString(Contacts.USERID, "")
        map["pageNo"] = pageIndex.toString()
        map["pageSize"]="10"
        map["deviceValue"] = AppUtils.encryptMD5(AppUtils.getDeviceImei())
        map["deviceType"] = "IMEI"
        RetrofitWorker.retrofitWorker.getRecommendPage(map)
                .subscribeOn(Schedulers.io())
                .map {
                    if (it.data != null && it.data!!.records.isNotEmpty()) {
                        for (item in it.data!!.records) {
                            it.data!!.recordss.add(AppUtils.parseGood(item))
                        }
                    }
                    it
                }
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(object : DisposableObserver<RemoteResultBean<UserCenterGoodBean>>(){
                    override fun onComplete() {

                    }

                    override fun onNext(it: RemoteResultBean<UserCenterGoodBean>) {
                        if (it.data!=null){
                            if (refresh){
                                goodsList.clear()
                                if (it.data!!.recordss.size>0){
                                    goodsList.addAll(it.data!!.recordss)
                                    //myAdapter!!.notifyItemRangeChanged(1,goodsList.size)
                                    myAdapter!!.notifyDataSetChanged()
                                    pageIndex++
                                }else{
                                    choiceness_smartrefresh.finishLoadMoreWithNoMoreData()
                                }
                            }else{
                                if (it.data!!.recordss.size>0){
                                    choiceness_smartrefresh.finishLoadMore()
                                    goodsList.addAll(it.data!!.recordss)
                                    myAdapter!!.notifyItemRangeChanged(1,goodsList.size)
                                    pageIndex++
                                }else{
                                    choiceness_smartrefresh.finishLoadMoreWithNoMoreData()
                                }
                            }
                        }
                    }

                    override fun onError(e: Throwable) {
                        if (refresh){

                        }else{
                            choiceness_smartrefresh.finishLoadMore()
                        }
                        if (e is OtherException){
                            //showToastMsg(e.msg)
                        }else{
                            showToastMsg("网络加载出错了！")
                        }
                    }
                })
    }
    private fun getAliLonginUrl(){
        showProgressDialog("加载中...")
        val map = HashMap<String, String>()
        map["userId"]=AppUtils.getString(Contacts.USERID,"")
        RetrofitWorker.retrofitWorker.getAuthUrl(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(object :DisposableObserver<RemoteResultBean<String>>(){
                    override fun onComplete() {

                    }

                    override fun onNext(it: RemoteResultBean<String>) {
                        dismissProgressDialog()
                        if (200==it.code){
                            val url=it.data?:""
                            if (url.isNotEmpty()){
                                val intent= Intent(context, WebActivity::class.java)
                                intent.putExtra("url", url)
                                intent.putExtra("name", "淘宝授权")
                                startActivity(intent)
                            }
                        }
                    }

                    override fun onError(e: Throwable) {
                        dismissProgressDialog()
                        if (e is OtherException){
                            if ("502"==e.code.toString()){

                            }else{
                                showToastMsg(e.msg)
                            }
                        }else{
                            showToastMsg("数据加载出错！")
                        }
                    }
                })
    }
    private fun getHotGoodsList(){
        val map=HashMap<String,String>()
        map["minId"]=pageIndex.toString()
        map["back"]="5"
        map["cid"]="0"
        RetrofitWorker.retrofitWorker.getDayLongHotSell(map)
                .subscribeOn(Schedulers.io())
                .map { DataUtils().hdkData(it) }
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(object : DisposableObserver<RemoteResultBean<HDKGoodsBean>>(){
                    override fun onComplete() {

                    }

                    override fun onNext(it: RemoteResultBean<HDKGoodsBean>) {
                        if (it.data!=null&&it.data!!.datas.isNotEmpty()){
                            goodsAllDayList.clear()
                            goodsAllDayList.addAll(it.data!!.datas!!)
                            val dataBean=TaobaoGoodBean()
                            dataBean.item_id=""
                            goodsAllDayList.add(dataBean)
                            myHotAdapter!!.notifyDataSetChanged()
                        }
                    }
                    override fun onError(e: Throwable) {
                        if (e is OtherException){
                            showToastMsg(e.msg)
                        }else{
                            showToastMsg("网络加载出错了！")
                            //Log.e("eeee","----->"+e.toString())
                        }
                    }

                })
    }
    private fun getBrandData(){
        val map= HashMap<String,String>()
        map["minId"]="1"
        map["back"]="5"
        map["brandcat"]="0"
        RetrofitWorker.retrofitWorker.getBrandListData(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(object : DisposableObserver<RemoteResultBean<BrandSpecialListBean>>(){
                    override fun onComplete() {

                    }

                    override fun onNext(it: RemoteResultBean<BrandSpecialListBean>) {
                        if (it.code==200&&it.data!=null&&it.data!!.data!=null){
                            if (it.data!!.data!!.isNotEmpty()){
                                brandList.clear()
                                brandList.addAll(it.data!!.data!!)
                                val dataBean=BrandSpecialData()
                                dataBean.id=""
                                brandList.add(dataBean)
                                myBrandAdapter!!.notifyDataSetChanged()
                            }
                        }
                    }

                    override fun onError(e: Throwable) {
                        if (e is OtherException){
                            showToastMsg(e.msg)
                        }else{
                            showToastMsg("网络加载出错了！")
                        }
                    }

                })
    }
    private inner class MyAdapter:RecyclerView.Adapter<RecyclerView.ViewHolder>(){
        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
            if (0==viewType){
                val view=LayoutInflater.from(parent.context).inflate(R.layout.item_choiceness_top,parent,false)
                return MyTopHolder(view)
            }else{
                val view=LayoutInflater.from(parent.context).inflate(R.layout.choiceness_rvitm,parent,false)
                return MyHolder(view)
            }
        }

        override fun getItemCount(): Int {
            return goodsList.size+1
        }

        override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
            if (holder is MyTopHolder){
                holder.msRv!!.layoutManager=LinearLayoutManager(context)
                msAdapter=MyMSAdapter()
                holder.msRv!!.adapter=msAdapter
            }else if (holder is MyHolder){
                if (goodsList.size>0){
                    val taobaoGoodBean=goodsList[position-1]
                    val df = DecimalFormat("#0.00")
                    holder.goodsTitle!!.text=taobaoGoodBean.title
                    if (taobaoGoodBean.has_coupon){
                        holder.goodsTextQh!!.text="券后"
                        holder.goodsCoupon!!.text=String.format("¥%s", taobaoGoodBean.coupon_price)
                        holder.couponLL!!.visibility=View.VISIBLE
                        holder.goodsOldPrice!!.text=taobaoGoodBean.zk_final_price
                    }else{
                        holder.goodsTextQh!!.text="抢"
                        holder.couponLL!!.visibility=View.INVISIBLE
                        holder.goodsOldPrice!!.text=taobaoGoodBean.reserve_price
                    }
                    holder.oldpriceType!!.text=taobaoGoodBean.goodsSource+"价"
                    holder.goodsType!!.setImageResource(taobaoGoodBean.userType)
                    holder.goodsAward!!.text="￥${taobaoGoodBean.vip_commission}"
                    holder.goodsPrice!!.text="￥${taobaoGoodBean.final_price}"
                    holder.goodsSales!!.text=taobaoGoodBean.volume
                    holder.shopName!!.text=taobaoGoodBean.shop_title
                    holder.shopType!!.setImageResource(taobaoGoodBean.userType)
                    Glide.with(activity!!).asBitmap()
                            .apply(RequestOptions().error(R.drawable.ic_app_place_holder3))
                            .load(taobaoGoodBean.pict_url)
                            .into(holder.goodsImag!!)
                    holder.itemView.setOnClickListener {
                        setIntent(taobaoGoodBean)
                    }
                }
            }
        }

        override fun getItemViewType(position: Int): Int {
            return if (position==0){
                0
            }else{
                1
            }
        }
    }
    private inner class MyTopHolder(itemview:View):RecyclerView.ViewHolder(itemview){
        var msRv:RecyclerView?=null
        var rvHot:RecyclerView?=null
        var rvBrand:RecyclerView?=null
        var clHot:ConstraintLayout?=null
        var clBrand:ConstraintLayout?=null
        init {
            msRv=itemview.choiceness_itemTopRv
            clHot=itemview.clAllDayTitle
            clBrand=itemview.clBrandTitle
            rvHot=itemview.rvAllDay
            rvBrand=itemview.rvBrand
            myHotAdapter=MyHotAdapter()
            rvHot!!.layoutManager=LinearLayoutManager(context,LinearLayoutManager.HORIZONTAL,false)
            rvHot!!.setHasFixedSize(true)
            rvHot!!.adapter=myHotAdapter
            getHotGoodsList()
            myBrandAdapter=MyBrandAdapter()
            rvBrand!!.layoutManager=LinearLayoutManager(context,LinearLayoutManager.HORIZONTAL,false)
            rvBrand!!.setHasFixedSize(true)
            rvBrand!!.adapter=myBrandAdapter
            getBrandData()
            clHot!!.setOnClickListener { startActivity(Intent(context!!,DaylongHotSellActivity::class.java)) }
            clBrand!!.setOnClickListener { startActivity(Intent(context!!,BrandSpecialActivity::class.java)) }
        }
    }
    private inner class MyHolder(itemview:View):RecyclerView.ViewHolder(itemview){
        var goodsTitle:TextView?=null
        var goodsImag:ImageView?=null
        var goodsOldPrice:TextView?=null
        var goodsPrice:TextView?=null
        var goodsCoupon:TextView?=null
        var goodsAward:TextView?=null
        var goodsSales:TextView?=null
        var goodsType:ImageView?=null
        var couponLL:LinearLayout?=null
        var goodsTextQh:TextView?=null
        var oldpriceType:TextView?=null
        var shopName:TextView?=null
        var shopType:ImageView?=null
        init {
            goodsTitle=itemView.choiceness_rvitm_title
            goodsImag=itemview.choiceness_rvitm_img
            goodsOldPrice=itemview.choiceness_rvitm_oldprice
            goodsPrice=itemview.choiceness_rvitm_price
            goodsCoupon=itemview.choiceness_rvitm_quanprice
            goodsAward=itemview.choiceness_rvitm_jiangprice
            goodsSales=itemview.choiceness_rvitm_yuenumber
            goodsType=itemview.choiceness_rvitm_imgtype
            couponLL=itemview.choiceness_rvitm_llq1
            goodsTextQh=itemView.choiceness_rvitm_qh
            oldpriceType=itemView.choiceness_rvitm_oldpricetype
            shopName=itemview.choiceness_rvitm_tvShopName
            shopType=itemview.choiceness_rvitm_ivGoodsType
            goodsOldPrice!!.paint.flags = Paint.STRIKE_THRU_TEXT_FLAG or Paint.ANTI_ALIAS_FLAG
        }
    }
    private inner class MyShopAdapter: RecyclerView.Adapter<RecyclerView.ViewHolder>(){
        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
            val view= LayoutInflater.from(parent.context).inflate(R.layout.choiceness_shoprvitm,parent,false)
            return MyShopHolder(view)
        }

        override fun getItemCount(): Int {
            return shopList.size
        }

        override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
            if (holder is MyShopHolder){
                if (shopList.size>0){
                    val url=shopList[position].imgPath?:""
                    if (url.isNotEmpty()&&url.contains(".gif")){
                        Glide.with(activity!!)
                                .asGif()
                                .apply(RequestOptions().error(R.drawable.ic_app_place_holder3))
                                .load(Contacts.NEWREMOTE_IMAGE_URL +url)
                                .into(holder.imageView!!)
                    }else{
                        Glide.with(activity!!)
                                .asBitmap()
                                .apply(RequestOptions().error(R.drawable.ic_app_place_holder3))
                                .load(Contacts.NEWREMOTE_IMAGE_URL +url)
                                .into(holder.imageView!!)
                    }
                    holder.textView!!.text=shopList[position].name
                    holder.itemView.setOnClickListener {
                        startShopIntent(shopList[position])
                    }
                }
            }
        }
    }
    inner class MyShopHolder(itemview: View): RecyclerView.ViewHolder(itemview){
        var textView: TextView?=null
        var imageView: ImageView?=null
        init {
            textView=itemview.choiceness_shoprvitm_name
            imageView=itemview.choiceness_shoprvitm_img
        }
    }
    private inner class MyMSAdapter:RecyclerView.Adapter<RecyclerView.ViewHolder>(){
        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
            val view= LayoutInflater.from(parent.context).inflate(R.layout.item_home_msrv,parent,false)
            return MyMSHolder(view)
        }

        override fun getItemCount(): Int {
            return msGoodsList.size
        }

        override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
            if (msGoodsList.isNotEmpty()){
                if (holder is MyMSHolder){
                    val taobaoGoodBean=msGoodsList[position]
                    val df = DecimalFormat("#0.0")
                    holder.goodsTitle!!.text="           ${taobaoGoodBean.title}"
                    holder.goodsOldPrice!!.text=taobaoGoodBean.zk_final_price
                    val price=taobaoGoodBean.final_price?:""
                    val olderPrice=taobaoGoodBean.zk_final_price?:""
                    if (msTitleList.isNotEmpty()){
                        val index=position%msTitleList.size
                        holder.tvMsTitle!!.text=msTitleList[index]
                    }
                    if (price.isNotEmpty()&&olderPrice.isNotEmpty()){
                        val zk=df.format(price.toDouble()/olderPrice.toDouble()*10)
                        val arr=zk.split(".")
                        if (arr[0].length>1){
                            holder.clZK!!.visibility=View.INVISIBLE
                        }else {
                            holder.clZK!!.visibility=View.VISIBLE
                            if (arr.size > 1) {
                                holder.goodsZKD!!.text = arr[0]
                                holder.goodsZKX!!.text = ".${arr[1]}"
                            }
                        }
                    }
                    holder.goodsTXNumber!!.text=taobaoGoodBean.volume.replace("月销","已抢")
                    if (msClassType==1){
                        holder.goodsTXNumber!!.visibility=View.VISIBLE
                        holder.goodsTX!!.text="马上抢"
                        holder.goodsTX!!.setBackgroundResource(R.drawable.shape_redff0038_5)
                    }else{
                        holder.goodsTXNumber!!.visibility=View.INVISIBLE
                        holder.goodsTX!!.text="提醒我"
                        holder.goodsTX!!.setBackgroundResource(R.drawable.shape_black_tm5)
                    }
                    holder.goodsPriceType!!.text="${taobaoGoodBean.goodsSource}价"
                    holder.goodsOldPrice!!.text="¥${taobaoGoodBean.zk_final_price}"
                    holder.goodsPrice!!.text=taobaoGoodBean.final_price
                    Glide.with(activity!!).asBitmap()
                            .apply(RequestOptions().error(R.drawable.ic_app_place_holder3))
                            .load(taobaoGoodBean.pict_url)
                            .into(holder.goodsImag!!)
                    holder.goodsTX!!.setOnClickListener {
                        if (msClassType==1){
                            setIntent(taobaoGoodBean)
                        }else {
                            if (System.currentTimeMillis() - mLasttime[0] > 1000) {
                                //防止快速点击操作
                                mLasttime[0] = System.currentTimeMillis()
                                if (msClickIndex == 4&&msStartTime.isNotEmpty()) {
                                    if (msTXTitle.isNotEmpty()) {
                                        CalendarReminderUtils.deleteCalendarEvent(context, msTXTitle)
                                    }
                                    val time=simpleDateFormat.parse(msStartTime).time
                                    CalendarReminderUtils.addCalendarEvent(context, msTXTitle, taobaoGoodBean.title, time, 1)
                                    showToastMsg("将在开抢前1分钟提醒！")
                                    //msTXTitle=taobaoGoodBean.title
                                } else if (msClickIndex == 5&&msStartTime1.isNotEmpty()) {
                                    if (msTXTitle1.isNotEmpty()) {
                                        CalendarReminderUtils.deleteCalendarEvent(context, msTXTitle1)
                                    }
                                    val time=simpleDateFormat.parse(msStartTime1).time
                                    CalendarReminderUtils.addCalendarEvent(context, msTXTitle1, taobaoGoodBean.title, time, 1)
                                    showToastMsg("将在开抢前1分钟提醒！")
                                }else{
                                    showToastMsg("数据出错，请稍后再试！")
                                }
                            }
                        }
                    }
                    holder.itemView.setOnClickListener {
                        if (msClassType==1) {
                            setIntent(taobaoGoodBean)
                        }else{
                            //showToastMsg("活动尚未开始")
                        }
                    }
                }
            }
        }
    }
    private inner class MyMSHolder(itemview: View):RecyclerView.ViewHolder(itemview){
        var goodsTitle: TextView?=null
        var goodsImag: ImageView?=null
        var goodsOldPrice: TextView?=null
        var goodsPrice: TextView?=null
        var goodsTXNumber: TextView?=null
        var clZK: ConstraintLayout?=null
        var goodsTX: TextView?=null
        var goodsZKD:TextView?=null
        var goodsZKX:TextView?=null
        var goodsPriceType:TextView?=null
        var tvMsTitle:TextView?=null
        init {
            goodsTitle=itemview.homeMSItem_tvGoodsname
            goodsImag=itemview.homeMSItem_ivGoods
            goodsOldPrice=itemview.homeMSItem_tvOldPrice
            goodsPrice=itemview.homeMSItem_tvPrice
            goodsTXNumber=itemview.homeMSItem_tvTXNumber
            goodsTX=itemview.homeMSItem_tvTX
            goodsZKD=itemview.homeMSItem_tvZKD
            goodsZKX=itemview.homeMSItem_tvZKX
            goodsPriceType=itemview.homeMSItem_tvOldPriceType
            clZK=itemview.homeMSItem_clZK
            tvMsTitle=itemview.tvMsTitle
            goodsOldPrice!!.paint.flags = Paint.STRIKE_THRU_TEXT_FLAG or Paint.ANTI_ALIAS_FLAG
        }
    }
    private inner class MyHotAdapter:RecyclerView.Adapter<RecyclerView.ViewHolder>(){
        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
            if (0==viewType){
                val view= LayoutInflater.from(parent.context).inflate(R.layout.rvitem_allday_hot,parent,false)
                return MyHotHolder(view)
            }else{
                val view= LayoutInflater.from(parent.context).inflate(R.layout.rvitem_brand_nodata,parent,false)
                return MyNoDataHolder(view)
            }
        }

        override fun getItemCount(): Int {
            return goodsAllDayList.size
        }
        override fun getItemViewType(position: Int): Int {
            if (goodsAllDayList.isNotEmpty()){
                val dataBean=goodsAllDayList[position]
                val id=dataBean.item_id?:""
                if (id.isNotEmpty()){
                    return 0
                }else{
                    return 1
                }
            }else {
                return super.getItemViewType(position)
            }
        }
        override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
            if (goodsAllDayList.isNotEmpty()){
                if (holder is MyHotHolder){
                    val good=goodsAllDayList[position]
                    val df = DecimalFormat("#0.00")
                    LoadUtils().loadRoundImag(context!!,holder.ivGoods!!,(good.pict_url as String)?:"",R.drawable.ic_good_place_holder,5)
                    holder.tvGoodsName!!.text =good.title
                    holder.tvPrice!!.text=good.final_price
                    holder.tvOldPrice!!.text=good.original_price
                    holder.tvGoodsDayNumber!!.text="今日成交${good.todaysale}件"
                    if (0==position){
                        holder.ivGoodsPM!!.visibility=View.VISIBLE
                        holder.ivGoodsPM!!.setImageResource(R.drawable.imag_hotsell_bd1)
                    }else if(1==position){
                        holder.ivGoodsPM!!.visibility=View.VISIBLE
                        holder.ivGoodsPM!!.setImageResource(R.drawable.imag_hotsell_bd2)
                    }else if(2==position){
                        holder.ivGoodsPM!!.visibility=View.VISIBLE
                        holder.ivGoodsPM!!.setImageResource(R.drawable.imag_hotsell_bd3)
                    }else{
                        holder.ivGoodsPM!!.visibility=View.INVISIBLE
                    }
                    holder.itemView.setOnClickListener {
                        val intent = Intent(context, GoodDetailActivity::class.java)
                        intent.putExtra("good", good)
                        startActivity(intent)
                    }
                }else if(holder is MyNoDataHolder){
                    holder.tvContent!!.text="查看更多"
                    holder.itemView.setOnClickListener {
                        startActivity(Intent(context!!,DaylongHotSellActivity::class.java))
                    }
                }
            }
        }

    }
    private inner class MyHotHolder(itemview:View):RecyclerView.ViewHolder(itemview){
        var ivGoods:ImageView?=null
        var ivGoodsPM:ImageView?=null
        var tvGoodsName:TextView?=null
        var tvGoodsDayNumber:TextView?=null
        var tvPrice:TextView?=null
        var tvOldPrice:TextView?=null
        init {
            ivGoods=itemview.ivGoods
            ivGoodsPM=itemview.ivRanking
            tvGoodsDayNumber=itemview.tvGoodsVolume
            tvGoodsName=itemview.tvGoodsName
            tvOldPrice=itemview.tvGoodsOldPrice
            tvPrice=itemview.tvGoodsPrice
            tvOldPrice!!.paint.flags = Paint.STRIKE_THRU_TEXT_FLAG or Paint.ANTI_ALIAS_FLAG
        }
    }
    private inner class MyBrandAdapter:RecyclerView.Adapter<RecyclerView.ViewHolder>(){
        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
            return if (0==viewType){
                val view= LayoutInflater.from(parent.context).inflate(R.layout.rvitem_brand,parent,false)
                MyBrandHolder(view)
            }else{
                val view= LayoutInflater.from(parent.context).inflate(R.layout.rvitem_brand_nodata,parent,false)
                MyNoDataHolder(view)
            }
        }

        override fun getItemCount(): Int {
            return brandList.size
        }

        override fun getItemViewType(position: Int): Int {
            if (brandList.isNotEmpty()){
                val dataBean=brandList[position]
                val id=dataBean.id?:""
                if (id.isNotEmpty()){
                    return 0
                }else{
                    return 1
                }
            }else {
                return super.getItemViewType(position)
            }
        }
        override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
            if (brandList.isNotEmpty()){
                if (holder is MyBrandHolder){
                    val dataBean=brandList[position]
                    val bgIndex=position%3
                    val ppName=dataBean.tb_brand_name?:""
                    if (0==bgIndex){
                        holder.ivZBBG!!.setBackgroundResource(R.drawable.imag_pp_top_k1)
                        holder.tvPPNameX!!.setTextColor(context!!.resources.getColor(R.color.golden_fec))
                        holder.tvPPNameD!!.setTextColor(context!!.resources.getColor(R.color.golden_fec))
                        holder.tvPPName!!.setTextColor(context!!.resources.getColor(R.color.golden_fec))
                    }else if (1==bgIndex){
                        holder.ivZBBG!!.setBackgroundResource(R.drawable.imag_pp_top_k2)
                        holder.tvPPNameX!!.setTextColor(context!!.resources.getColor(R.color.golden_fec))
                        holder.tvPPNameD!!.setTextColor(context!!.resources.getColor(R.color.golden_fec))
                        holder.tvPPName!!.setTextColor(context!!.resources.getColor(R.color.golden_fec))
                    }else if(2==bgIndex){
                        holder.ivZBBG!!.setBackgroundResource(R.drawable.imag_pp_top_k3)
                        holder.tvPPNameX!!.setTextColor(context!!.resources.getColor(R.color.white))
                        holder.tvPPNameD!!.setTextColor(context!!.resources.getColor(R.color.white))
                        holder.tvPPName!!.setTextColor(context!!.resources.getColor(R.color.white))
                    }
                    if (ppName.contains("/")){
                        val arr=ppName.split("/")
                        holder.tvPPNameX!!.visibility=View.VISIBLE
                        holder.tvPPNameD!!.visibility=View.VISIBLE
                        holder.tvPPName!!.visibility=View.GONE
                        if (arr.size>1){
                            holder.tvPPNameD!!.text=arr[0]
                            holder.tvPPNameX!!.text=arr[1]
                        }else{
                            holder.tvPPNameD!!.text=ppName
                            holder.tvPPNameX!!.visibility=View.GONE
                        }
                    }else{
                        holder.tvPPName!!.text=ppName
                        holder.tvPPNameX!!.visibility=View.GONE
                        holder.tvPPNameD!!.visibility=View.GONE
                        holder.tvPPName!!.visibility=View.VISIBLE
                    }
                    if (dataBean.item!=null&&dataBean.item!!.isNotEmpty()){
                        val itemBean=dataBean.item!![0]
                        LoadUtils().loadRoundImag(context!!,holder.ivGoods!!,itemBean.itempic?:"",R.drawable.ic_good_place_holder,5)
                        holder.tvGoodsName!!.text=itemBean.itemtitle?:""
                        holder.tvOldPrice!!.text=itemBean.itemprice?:"0"
                        holder.tvPrice!!.text=itemBean.itemendprice?:"0"
                    }
                    holder.itemView.setOnClickListener {
                        val intent=Intent(holder.itemView.context, BrandSpecialListActivity::class.java)
                        intent.putExtra("Name",dataBean.tb_brand_name?:"")
                        intent.putExtra("Id",dataBean.id?:"")
                        startActivity(intent)
                    }
                }else if(holder is MyNoDataHolder){
                    holder.tvContent!!.text="更多品牌"
                    holder.itemView.setOnClickListener { startActivity(Intent(context!!,BrandSpecialActivity::class.java)) }
                }
            }
        }

    }
    private inner class MyBrandHolder(itemview:View):RecyclerView.ViewHolder(itemview){
        var ivGoods:ImageView?=null
        var ivZBBG:ImageView?=null
        var tvGoodsName:TextView?=null
        var tvPrice:TextView?=null
        var tvOldPrice:TextView?=null
        var tvPPNameD:TextView?=null
        var tvPPNameX:TextView?=null
        var tvPPName:TextView?=null
        init {
            ivGoods=itemview.ivBranGoods
            ivZBBG=itemview.ivBranZBBG
            tvGoodsName=itemview.tvBranGoodsName
            tvOldPrice=itemview.tvBranGoodsOldPrice
            tvPrice=itemview.tvBranGoodsPrice
            tvPPNameD=itemview.tvBrandNameD
            tvPPNameX=itemview.tvBrandNameX
            tvPPName=itemview.tvBrandName
            tvOldPrice!!.paint.flags = Paint.STRIKE_THRU_TEXT_FLAG or Paint.ANTI_ALIAS_FLAG
        }
    }
    private inner class MyNoDataHolder(itemview:View):RecyclerView.ViewHolder(itemview){
        var tvContent:TextView?=null
        init {
            tvContent=itemview.tvMessage
        }
    }
    inner class GlideImageLoader: ImageLoader(){
        override fun displayImage(context: Context, path: Any, imageView: ImageView) {
            val pading= AppUtils.dip2px(context,12f)
            imageView.setPadding(pading,0,pading,0)
            val topBanner=path as TopBanner
            Glide.with(context).asBitmap()
                    .apply(RequestOptions().transforms(CenterCrop(), RoundedCorners( 30)).error(R.drawable.ic_app_place_holder2))
                    .load(Contacts.NEWREMOTE_IMAGE_URL +topBanner.imgPath)
                    .into(imageView)
        }
    }
}